package com.zhiwei.msf.common.config;

import java.util.Properties;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertiesPropertySource;

/**
 * @author ZHIWEI.YANG
 * @time 2019/11/17 - 19:21
 * @decription 默认mybatis配置
 */
@Configuration
@MapperScan(basePackages = { "com.zhiwei.msf.**.mapper" })
public class MybatisConfig implements InitializingBean {

	@Autowired
	private Environment environment;

	@Override
	public void afterPropertiesSet() throws Exception {
		ConfigurableEnvironment c = (ConfigurableEnvironment) environment;
		MutablePropertySources m = c.getPropertySources();
		Properties properties = new Properties();
		// mybatis mapper xml文件映射
		properties.put("mybatis.mapperLocations",
				new String[] { "classpath:/**/mapper/*.xml", "classpath:/**/extmapper/*.xml" });
		m.addFirst(new PropertiesPropertySource("defaultProperties", properties));
	}
}
